<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\admin\model\TaskRecord;

class order extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('app\command\order');
        // 设置参数
    }

    protected function execute(Input $input, Output $output)
    {
    	// 指令输出
		$taskRecord =   new TaskRecord();
		$task_record =$taskRecord
            ->whereTime('begin_time', '>=',date('Y/m/d'))
            ->where('order_status', '0')
                        ->order('task_record_id','asc')
                        ->limit(20)
						->select();
		if (empty($task_record)){
		    exit('dsfdsf');
        }

		if($task_record){
			$task_record = $task_record->toArray();
		}

		$taks_id = [];
		$task = [];
		foreach($task_record  as $val){
		  $taks_id[$val['order_id']] = $val['task_record_id'];
		  $task[$val['order_id']] = $val;
		}
		$order_id = array_column($task_record,'order_id');
		$api_where = [
		 'id'=>join(',',array_filter($order_id))
		];
		$encode_param =_create_sign('/ll/task_list',$api_where);
		$result =curl_request(config('lieliu.url').'/ll/task_list','post',$encode_param);
		$list = isset($result['data']['list']['l']) ? $result['data']['list']['l'] : [];
		$update_param  = [];
		foreach($list as $key=>$val){
		    dump(($task[$val['i']]['count']-$val['e']));
			$update_param[$key]['task_record_id'] = $taks_id[$val['i']];
			$update_param[$key]['order_id'] = $val['i'];
			$update_param[$key]['complete_count'] =$task[$val['i']]['count']-$val['e'];
                $update_param[$key]['complete_show'] =($task[$val['i']]['show']/$task[$val['i']]['count'])*($task[$val['i']]['count']-$val['e']);
			$update_param[$key]['order_status'] = $val['s'];
		}
		var_dump($update_param);
		$taskRecord ->saveAll($update_param);
    	$output->writeln('app\command\order');
    }
}
